﻿using Item;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Player.ItemRandom
{
    public class NormalRandomer : IItemRandomer
    {
        public string[] GetRandomItems(string[] types, int num)
        {
            List<string> listTags=new List<string>();
            List<int> listWeight = new List<int>();

            List<string> listTypes = new List<string>();
            listTypes.AddRange(types);

            int sameTypeCount = 0;
            foreach (var item in ItemDataMgr.Ins.AllItemData)
            {
                sameTypeCount = 0;
                //统计匹配类型的数量
                for (int i = 0; i < item.arrItemRandomTag.Length; i++)
                {
                    if (listTypes.Contains(item.arrItemRandomTag[i]))
                    {
                        sameTypeCount++;
                    }
                }

                if (sameTypeCount > 0)
                {
                    listTags.Add(item.strItemTag);
                    //匹配标签越多，权重越高，*2 增长
                    listWeight.Add((int)(item.nRandomWeight * Mathf.Pow(2, sameTypeCount - 1)));
                }
            }

            var get = SangsTools.MyRandomTools.RandomWithWeight<string>(listTags.ToArray(), listWeight.ToArray(), num);
            return get;
        }
    }

}